package bmptest.bmp.service.Sysmenu;

import bmptest.bmp.entity.SysMenu;
import bmptest.bmp.mapper.SysMenu.SysMenuMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SysMenuService {

    @Autowired
    SysMenuMapper sysMenuMapper;

    public List<SysMenu> querySysMenu(){
        List<SysMenu> l = sysMenuMapper.querySysMenu();
        return l;
    }

    public List<SysMenu> querySysMenu1(String roleid){
        List<SysMenu> l = sysMenuMapper.querySysMenu1(roleid);
        return l;
    }

    public String queryRoleIdByUserId(String userid){
        String roleid = sysMenuMapper.queryRoleIdByUserId(userid);
        return roleid;
    }


    public List<SysMenu> buildtree(List<SysMenu> listallmenu,String parent_id){
        List<SysMenu> treeList = new ArrayList<>();
        listallmenu.forEach(menu -> {
            if (StringUtils.equals(parent_id, menu.getParent_id())) {
                menu.setChildMenus(buildtree(listallmenu, menu.getMenu_id()));
                treeList.add(menu);
            }
        });
        return treeList;
    }

}
